<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">工单编号：</label>
                  <div class="layui-input-inline">
                    <input name="code" class="layui-input" type="text" placeholder="工单编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">制造令编号：</label>
                  <div class="layui-input-inline">
                    <input name="planCode" class="layui-input" type="text" placeholder="制造令编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">车间：</label>
                  <div class="layui-input-inline">
                    <input name="workshopName" class="layui-input" type="text" placeholder="车间名称" />
                  </div>
                </div>

                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料编码：</label>
                  <div class="layui-input-inline">
                    <input name="skuCode" class="layui-input" type="text" placeholder="物料编码" />
                  </div>
                </div>

                <div class="layui-inline">
                  <label class="layui-form-label w-auto">工种：</label>
                  <div class="layui-input-inline">
                    <input name="deviceTypeNames" class="layui-input" type="text" placeholder="工种" />
                  </div>
                </div>

                <div class="layui-inline">
                  <label class="layui-form-label w-auto">工序编码：</label>
                  <div class="layui-input-inline">
                    <input name="processCode" class="layui-input" type="text" placeholder="工序编码" />
                  </div>
                </div>
                <!-- <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料名称：</label>
                  <div class="layui-input-inline">
                    <input
                      name="skuName"
                      class="layui-input"
                      type="text"
                      placeholder="物料名称"
                    />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料编码：</label>
                  <div class="layui-input-inline">
                    <input
                      name="skuCode"
                      class="layui-input"
                      type="text"
                      placeholder="物料名称"
                    />
                  </div>
                </div> -->
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">工单状态：</label>
                  <div class="layui-input-inline">
                    <select id="status" name="status"></select>
                  </div>
                </div>
                <!-- <div class="layui-inline">
                  <label class="layui-form-label w-auto">设备：</label>
                  <div class="layui-input-inline">
                    <select name="deviceCode" id="selectDeviceCode">
                      <option value="">选择设备</option>
                    </select>
                  </div>
                </div> -->
                <!-- <div class="layui-inline">
                  <label class="layui-form-label w-auto">工序：</label>
                  <div class="layui-input-inline">
                    <select name="processId" id="selectProcessId">
                      <option value="">选择工序</option>
                    </select>
                  </div>
                </div> -->
                <!-- <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料类别：</label>
                  <div class="layui-input-inline">
                    <input name="keyWord" class="layui-input" type="text" />
                  </div>
                </div> -->
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">创建时间：</label>
                  <div class="layui-input-inline">
                    <input id="pTime" class="layui-input date-icon" type="text" placeholder="选择时间" style="width: 200px"
                      readonly />
                  </div>
                  <input name="startCreateTime" id="sTime" type="hidden" />
                  <input name="endCreateTime" id="eTime" type="hidden" />
                </div>

                <!-- 计划完工时间 -->
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">计划完工时间：</label>
                  <div class="layui-input-inline">
                    <input id="predictFinishTime" class="layui-input date-icon" type="text" placeholder="选择时间范围"
                      style="width: 200px" readonly />
                  </div>
                  <input name="startPredictFinishTime" id="startPredictFinishTime" type="hidden" />
                  <input name="endPredictFinishTime" id="endPredictFinishTime" type="hidden" />
                </div>

                <!-- 开工时间 -->
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">开工时间：</label>
                  <div class="layui-input-inline">
                    <input id="predictStartTime" class="layui-input date-icon" type="text" placeholder="选择时间范围"
                      style="width: 200px" readonly />
                  </div>
                  <input name="startPredictStartTime" id="startPredictStartTime" type="hidden" />
                  <input name="endPredictStartTime" id="endPredictStartTime" type="hidden" />
                </div>

                <!-- 交货时间 -->
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">交货时间：</label>
                  <div class="layui-input-inline">
                    <input id="shipmentTime" class="layui-input date-icon" type="text" placeholder="选择时间范围"
                      style="width: 200px" readonly />
                  </div>
                  <input name="startShipmentTime" id="startShipmentTime" type="hidden" />
                  <input name="endShipmentTime" id="endShipmentTime" type="hidden" />
                </div>

              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>
                    查询
                  </button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                    重置
                  </button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button type="button" id="configFun" style="display: none" class="layui-btn icon-btn">
                确认选择
              </button>
            </div>
            <div class="lay-btn-rt"></div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="productionWorkOrderTable" lay-filter="productionWorkOrderTable"></table>
    </div>
  </div>
</div>
<style>
  .left-btn {
    flex: 1;
    text-align: left;
  }

  .flex-between {
    width: calc(100% - 40px);
    display: flex;
    justify-content: space-between;
  }

  .productionWorkOrderAddForm .layui-form-item .layui-input-inline {
    width: 290px;
  }

  .productionWorkOrderAddForm .w-auto {
    width: 100px !important;
  }

  .selectProductDetail .layui-table-cell {
    height: auto;
  }

  body .layui-table tbody tr.disabledBg {
    background-color: #f5f5f5 !important;
  }

  .layui-table-page-left {
    text-align: left;
  }

  .scroll-table-5-4 .layui-table-body {
    max-height: 535px;
  }

  .scroll-table-4-5 .layui-table-body {
    max-height: 490px;
  }
</style>
<!-- 表格操作列 -->
<script type="text/html" id="productionWorkOrderTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"
    >详情</a
  >
  <!-- {{# if(d.status=="toactivate"){ }} -->
  <a class="layui-btn layui-btn-xs" lay-event="activate">开工</a>
  <a class="layui-btn layui-btn-xs" lay-event="printDoc">打印</a>
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a> -->
  <!-- {{# }else if(d.status =="inproduction"){ }} -->
  <!-- <a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="createTask"
    >生成质检任务</a
  > -->
  <!-- <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="pause">暂停</a> -->
  <!-- {{# }else if(d.status =="termination"){ }} -->
  <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="activate">开工</a>
  <!-- {{# } }} -->
</script>

<!--开工单详情-->
<script id="productionWorkOrderTemplate" type="text/html">
  <form lay-filter="productionWorkOrderForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-form-item">
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">工单编号：</label>
              <div class="layui-input-inline">
                <input
                  name="code"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">生产计划：</label>
              <div class="layui-input-inline">
                <input
                  name="productionPlanCode"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">所属工序：</label>
              <div class="layui-input-inline">
                <input
                  name="processName"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <!-- <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">责任类型：</label>
              <div class="layui-input-inline">
                <input
                  name="deviceCode"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div> -->
          <!-- <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">工单性质：</label>
              <div class="layui-input-inline">
                <input
                  name="orderTypeDesc"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div> -->
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">物料编码：</label>
              <div class="layui-input-inline">
                <input
                  name="skuCode"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">排产数量：</label>
              <div class="layui-input-inline">
                <input
                  name="outputQuantity"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">完成数量：</label>
              <div class="layui-input-inline">
                <input
                  name="finishQuantity"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">领料数量：</label>
              <div class="layui-input-inline">
                <input
                  name="getQuantityQ"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">报工数量：</label>
              <div class="layui-input-inline">
                <input
                  name="reportedQuantity"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">合格数量：</label>
              <div class="layui-input-inline">
                <input
                  name="acceptanceQuantityQ"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto"
                >状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：</label
              >
              <div class="layui-input-inline">
                <input
                  name="statusDesc"
                  class="layui-input br0"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">工艺要求：</label>
              <div class="layui-input-block">
                <textarea name="content" class="layui-textarea" readonly></textarea>
              </div>
            </div>
          </div>
          <div class="layui-col-xs3">
            <div class="layui-form-item">
              <label class="layui-form-label w-auto">图纸：</label>
              <div class="layui-input-inline" style="width: 100%;" id="imgDiv">
                <img src="" alt="" />
              </div>
            </div>
          </div>
        </div>
        <div
          class="layui-tab layui-tab-brief"
          style="margin: 0;display: flex; flex-direction: column;"
        >
          <ul class="layui-tab-title">
            <li class="layui-this">排产信息</li>
            <li>领料记录</li>
            <li>报工记录</li>
            <li>质检记录</li>
            <li>图纸管理</li>
          </ul>
          <div class="layui-tab-content" style="flex: 1;padding: 0">
            <div class="layui-tab-item layui-show">
              <!-- 排产信息 -->
              <div class="layui-row">
                <div class="layui-col-md6" style="padding-right: 25px">
                  <div class="layui-form-item" style="margin-bottom: 10px">
                    <div class="open-details-title">关联几种/机型</div>
                  </div>
                  <table
                    class="layui-table"
                    id="deviceTable"
                    lay-filter="deviceTable"
                  ></table>
                </div>
                <div class="layui-col-md6">
                  <div class="layui-form-item" style="margin-bottom: 10px">
                    <div class="open-details-title">关联物料</div>
                  </div>
                  <table
                    class="layui-table"
                    id="relevanceMaterialTable"
                    lay-filter="relevanceMaterialTable"
                  ></table>
                </div>
              </div>
            </div>
            <div class="layui-tab-item ">
              <!-- 领料记录 -->
              <table
                class="layui-table"
                id="receiptRecordTable"
                lay-filter="receiptRecordTable"
              ></table>
            </div>
            <div class="layui-tab-item">
              <!-- 报工记录 -->
              <table
                class="layui-table"
                id="reportWorkRecordTable"
                lay-filter="reportWorkRecordTable"
              ></table>
            </div>
            <div class="layui-tab-item">
              <!-- 质检记录 -->
              <table
                class="layui-table"
                id="checkRecordTable"
                lay-filter="checkRecordTable"
              ></table>
            </div>
            <div class="layui-tab-item">
              <!-- 质检记录 -->
              <table
                class="layui-table"
                id="drawImageTable"
                lay-filter="drawImageTable"
              ></table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </form>
</script>

<!-- 领料记录表格操作列 -->
<script type="text/html" id="receiptRecordTabBar">
  <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
</script>

<!-- 领料记录详情弹窗 -->
<script type="text/html" id="receiptRecordDetailForm">
  <form lay-filter="receiptRecordDetailForm" class="layui-form model-form">
    <input name="id" type="hidden" />
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">开工单编号</label>
        <div class="layui-input-block">
          <input
            name="workOrderCode"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">制造令编号</label>
        <div class="layui-input-block">
          <input name="processCode" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">所属计划</label>
        <div class="layui-input-block">
          <input
            name="productionPlanCode"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">仓库类型</label>
        <div class="layui-input-block">
          <input
            name="warehouseTypeName"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">领料仓库</label>
        <div class="layui-input-block">
          <input
            name="receiptWarehouseName"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">领料料号数</label>
        <div class="layui-input-block">
          <input name="receiptNum" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">审核人</label>
        <div class="layui-input-block">
          <input
            name="auditPersonName"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">领料人</label>
        <div class="layui-input-block">
          <input name="creatorName" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
          <input name="remark" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs4">
      <div class="layui-form-item">
        <label class="layui-form-label">审核结果</label>
        <div class="layui-input-block">
          <textarea
            name="auditResult"
            placeholder="请输入审核结果"
            maxlength="200"
            class="layui-textarea"
          ></textarea>
        </div>
      </div>
    </div>
    <div class="layui-form-item" style="margin-left: 20px;">
      <div class="addReceiptRecordDetailForm-title">
        <h3 class="title">领料明细</h3>
      </div>
      <div class="line"></div>
      <!-- 表格 -->
      <table
        class="layui-table"
        id="receiptRecordDetailTable"
        lay-filter="receiptRecordDetailTable"
      ></table>
    </div>
  </form>
</script>

<!-- 报工记录表格操作列 -->
<script type="text/html" id="reportWorkOrderTableBar">
  <a class="layui-btn layui-btn-xs" lay-event="reportWorkDetail">详情</a>
</script>

<!--报工单详情-->
<script id="reportWorkOrderDetailForm" type="text/html">
  <form lay-filter="reportWorkOrderDetailForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-form-item">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">开工单信息</div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >开工单编码：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="workOrderCode"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >所属生产计划：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="planCode"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >排产工序：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="processName"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >物料类型：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="productTypeName"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >物料编号：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="skuCode"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >物料名称：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="skuName"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >内部规格码：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="skuSpec"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >排产数量：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="productionQuantity"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >已完工数量：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="finishQuantity"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
          <div class="layui-col-xs4">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 135px;"
                >备注：</label
              >
              <div
                class="layui-input-block"
                style="margin-left: 165px; width: 55%;"
              >
                <input
                  name="workRemark"
                  class="layui-input"
                  type="text"
                  readonly="readonly"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-form-item" style="margin-bottom: 10px;">
            <div class="open-details-title">工序报工信息</div>
          </div>
          <table
            class="layui-table"
            id="theProcessTable"
            lay-filter="theProcessTable"
          ></table>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 135px;"
            >报工图片：</label
          >
          <div class="layui-upload-drag cardU" id="pictureDiv">
            <!--<i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>-->
            <input
              type="hidden"
              name="reportWorkPic"
              lay-verify=""
              data-name="报工图片"
            />
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >仓库类型：</label
            >
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                name="warehouseTypeName"
                class="layui-input"
                type="text"
                readonly="readonly"
              />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >入库仓库：</label
            >
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                name="warehouseName"
                class="layui-input"
                type="text"
                readonly="readonly"
              />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >自检状态：</label
            >
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                name="reportWorkCheckStatusName"
                class="layui-input"
                type="text"
                readonly="readonly"
              />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >报工数量：</label
            >
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                name="workQuantity"
                class="layui-input"
                type="text"
                lay-verify="number"
              />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4" id="checkStatusDiv">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;"
              >审核状态：</label
            >
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                name="checkStatusDesc"
                class="layui-input"
                type="text"
                readonly="readonly"
              />
            </div>
          </div>
        </div>
        <div class="layui-col-xs4">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">备注：</label>
            <div
              class="layui-input-block"
              style="margin-left: 165px; width: 55%;"
            >
              <input
                id="reportWorkRemark"
                name="reportWorkRemark"
                class="layui-input"
                type="text"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </form>
</script>

<!-- 质检记录表格操作列 -->
<script type="text/html" id="qualityTestingRecordTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="details"
    >详情</a
  >
</script>

<!--添加开工单-->
<script id="productionWorkOrderAddTemplate" type="text/html">
  <form lay-filter="productionWorkOrderAddForm" class="layui-form model-form">
    <input name="id" type="hidden" />
    <input name="processId" type="hidden" />
    <input name="productionPlanId" type="hidden" />
    <input name="workOrderQuality" type="hidden" />
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">生产任务：</label>
        <div class="layui-input-block">
          <select
            id="productionProcessDeviceId"
            name="productionProcessDeviceId"
            lay-filter="selectProductionProcessDevice"
            lay-search
          ></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">制造令编号：</label>
        <div class="layui-input-block">
          <input name="planCode" type="text" class="layui-input" readonly />
          <input
            name="productionPlanRecordId"
            type="hidden"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">工站：</label>
        <div class="layui-input-block">
          <input name="deviceName" type="text" class="layui-input" readonly />
          <input name="deviceCode" type="hidden" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">产品料号：</label>
        <div class="layui-input-block">
          <input name="skuCode" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">产品规格：</label>
        <div class="layui-input-block">
          <input name="skuSpec" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">制造令编码：</label>
        <div class="layui-input-block">
          <input
            name="productionPlanRecordCode"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">工序名称：</label>
        <div class="layui-input-block">
          <input name="processName" type="text" class="layui-input" readonly />
          <input
            name="productionProcessId"
            type="hidden"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">计划排产数：</label>
        <div class="layui-input-block">
          <input
            name="planProductionQuantity"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">已认领数：</label>
        <div class="layui-input-block">
          <input
            name="outputQuantity"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">待认领数：</label>
        <div class="layui-input-block">
          <input
            id="waitProductionQuantity"
            name="waitProductionQuantity"
            type="text"
            class="layui-input"
            readonly
          />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">排产时间：</label>
        <div class="layui-input-block">
          <input name="createTime" type="text" class="layui-input" readonly />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">本次认领数量：</label>
        <div class="layui-input-block">
          <input name="claimQuantity" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button
        class="layui-btn layui-btn-primary"
        type="button"
        ew-event="closeDialog"
      >
        取消
      </button>
      <button
        class="layui-btn"
        lay-filter="productionWorkPlanFormSubmit"
        lay-submit
      >
        提交
      </button>
    </div>
  </form>
</script>

<!--打印销售弹窗-->
<script type="text/html" id="printFinishedOrderTemplate">
  <form lay-filter="printFinishedOrderTemplateForm" class="layui-form open-form printTemplateForm">
    <div class="open-model">
      <div class="open-auto">
        <div class="my-print-box" id="printHtml">

        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" type="button" id="printPurchaseOrder">打印</button>
      </div>
    </div>
  </form>
</script>
<script src="/admin/assets/libs/jquery/jquery-3.2.1.min.js"></script>
<script src="/admin/assets/libs/jquery/jQuery.print.js.js"></script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", 'laydate'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    let nowData = {};
    let where = {};
    if (typeof parentData !== "undefined") {
      nowData = { ...parentData };
      if (nowData.eventName == "radio" || nowData.eventName == "checkbox") {
        $("#configFun").show();
      }
      where = { ...nowData.where };
    }

    var laydate = layui.laydate;

    //时间范围
    laydate.render({
      elem: '#pTime',
      type: 'date',
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("#sTime").val(dateValue[0] + " 00:00:00");
          $("#eTime").val(dateValue[1] + " 23:59:59");
        } else {
          $("#sTime").val();
          $("#eTime").val();
        }
      }
    });

    // 计划完工时间范围选择器
    laydate.render({
      elem: '#predictFinishTime',
      type: 'date',
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("#startPredictFinishTime").val(dateValue[0] + " 00:00:00");
          $("#endPredictFinishTime").val(dateValue[1] + " 23:59:59");
        } else {
          $("#startPredictFinishTime").val("");
          $("#endPredictFinishTime").val("");
        }
      }
    });

    // 开工时间范围选择器
    laydate.render({
      elem: '#predictStartTime',
      type: 'date',
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("#startPredictStartTime").val(dateValue[0] + " 00:00:00");
          $("#endPredictStartTime").val(dateValue[1] + " 23:59:59");
        } else {
          $("#startPredictStartTime").val("");
          $("#endPredictStartTime").val("");
        }
      }
    });

    // 交货时间范围选择器
    laydate.render({
      elem: '#shipmentTime',
      type: 'date',
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("#startShipmentTime").val(dateValue[0] + " 00:00:00");
          $("#endShipmentTime").val(dateValue[1] + " 23:59:59");
        } else {
          $("#startShipmentTime").val("");
          $("#endShipmentTime").val("");
        }
      }
    });

    //工单状态
    admin.getDictList(
      "status",
      "production_work_order_status",
      null,
      "工单状态"
    );
    //初始化物料类别
    // admin.initDataSelectTree(
    //   true,
    //   "enterprise/product/admin/productType/getTreeData",
    //   null,
    //   "selectProductType",
    //   null,
    //   "物料类别",
    //   "productTypeId",
    //   null
    // );

    // 渲染表格
    var insTb = table.render({
      elem: "#productionWorkOrderTable",
      url:
        config.base +
        "production/productionPlan/admin/productionWorkOrder/list",
      page: true,
      cellMinWidth: 100,
      where: { ...where },
      cols: [
        [
          {
            type: "radio",
            hide: nowData.eventName == "radio" ? false : true,
          },
          { type: "numbers", align: "center", title: "序号" },
          { field: "code", align: "center", title: "开工单编号", width: 160 },
          {
            field: "productionPlanRecordCode",
            align: "center",
            title: "所属制造令",
            width: 160,
          },
          {
            field: "processName",
            align: "center",
            title: "所属工序",
          },
          { field: "processTypeName", align: "center", title: "工序属性" },
          { field: "deviceTypeNames", align: "center", title: "机型/工种" },
          // { field: "orderTypeDesc", align: "center", title: "工单性质" },
          { field: "skuName", align: "center", title: "物料名称" },
          { field: "skuCode", align: "center", title: "物料编码" },
          { field: "productionQuantity", align: "center", title: "总计划数量" },
          { field: "outputQuantity", align: "center", title: "本次排产数" },
          // { field: "finishQuantity", align: "center", title: "完成数" },
          { field: "canGetQuantity", align: "center", title: "可领用数量" },
          { field: "workQuantityTotal", align: "center", title: "报工数" },
          { field: "sendQuantityTotal", align: "center", title: "送检数" },
          { field: "acceptanceQuantity", align: "center", title: "合格数" },
          // { field: "scrapQuantity", align: "center", title: "报废数" },
          { field: "ypOkRate", align: "center", title: "样品合格率(%)" },
          { field: "bgOkRate", align: "center", title: "报工合格率(%)" },
          // { field: "finishQuantity", align: "center", title: "完成数" },
          {
            field: "createTime",
            align: "center",
            title: "创建时间",
            width: 160,
          },
          // , {field: 'predictStartTime', align: 'center', title: '预计开始时间', width: 160},
          // , {field: 'predictFinishTime', align: 'center', title: '预计完工时间', width: 160}
          { field: "statusDesc", align: "center", title: "状态" },
          {
            align: "center",
            toolbar: "#productionWorkOrderTableBar",
            title: "操作",
            fixed: "right",
            width: 300,
          },
        ],
      ],
    });
    $("#configFun").click(function () {
      let list = table.checkStatus("productionWorkOrderTable").data;
      childData.list = list;
      layer.close(nowData.zindex);
    });
    // 获取设备
    // admin.req(
    //   "enterprise/device/admin/device/getAll",
    //   {},
    //   function (res) {
    //     if (res.code == 200) {
    //       $.each(res.data, function (index, item) {
    //         $("#selectDeviceCode").append(
    //           new Option(item.deviceCode, item.deviceCode)
    //         );
    //       });
    //       form.render("select");
    //     } else {
    //       layer.msg(res.msg, { icon: 2 });
    //     }
    //   },
    //   "GET"
    // );

    // 工序名称
    admin.req(
      "enterprise/product/admin/processInfo/getAllProcessInfo",
      {},
      function (res) {
        if (res.code == 200) {
          $.each(res.data, function (index, item) {
            $("#selectProcessId").append(new Option(item.nodeNames, item.id));
          });
          form.render("select");
        } else {
          layer.msg(res.msg, { icon: 2 });
        }
      },
      "GET"
    );

    // 物料类型
    admin.req(
      "enterprise/product/admin/productType/getProductTypeVOAll",
      {},
      function (res) {
        if (res.code == 200) {
          $.each(res.data, function (index, item) {
            $("#selectProductTypeId").append(new Option(item.name, item.id));
          });
          form.render("select");
        } else {
          layer.msg(res.msg, { icon: 2 });
        }
      },
      "GET"
    );

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload(
        { where: { ...data.field, ...where }, page: { curr: 1 } },
        "data"
      );
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      insTb.reload(
        {
          where: { ...admin.resetSearch(data.field), ...where },
          page: { curr: 1 },
        },
        "data"
      );
    });

    form.render("select");
    function printDoc(data) {
      showPrintFinishedOrderTemplate(data);
      return
    }

    // 工具条点击事件
    table.on("tool(productionWorkOrderTable)", async function (obj) {
      var data = obj.data;

      if (obj.event === "activate") {
        //开工
        operationWorkOrder(data.id, 0, "确定要开工吗？", data);
      } else if (obj.event === "pause") {
        // 暂停
        operationWorkOrder(data.id, 1, "确定要暂停吗？", data);
      } else if (obj.event === "printDoc") {
        // 暂停
        printDoc(data);
      } else if (obj.event === "close") {
        // 关闭
        operationWorkOrder(data.id, 2, "确定要关闭吗？", data);
      } else if (obj.event === "detail") {
        // 详情
        const res = await admin.reqPro(
          "production/productionPlan/admin/productionWorkOrder/detail/" +
          data.id
        );
        console.log(33333, res);

        productionWorkOrderDetailModel(res.data);

        // table.reload("deviceTable", {
        //   data: []
        // });

        // table.reload("relevanceMaterialTable", {
        //   data: [...res.data.skuList]
        // });
        // 设备机型列表
        table.render({
          elem: "#deviceTable",
          data: [...res.data.deviceTypeList],
          cellMinWidth: 100,
          page: false,
          cols: [
            [
              { type: "numbers", title: "序号", fixed: "left" },
              { field: "id", title: "ID", hide: true },
              {
                field: "deviceName",
                align: "center",
                title: "类型名称",
                fixed: "left",
              },
              { field: "deviceCode", align: "center", title: "类型编号" },
            ],
          ],
        });
        // 关联物料表格
        table.render({
          elem: "#relevanceMaterialTable",
          data: [...res.data.skuList],
          cellMinWidth: 100,
          page: false,
          cols: [
            [
              { type: "numbers", width: 40, title: "序号" },
              { field: "skuCode", title: "物料编码", align: "center" },
              { field: "skuName", title: "物料名称", align: "center" },
              { field: "quantity", title: "需求数量", align: "center" },
              { field: "countQuantity", title: "需求总数量", align: "center" },
            ],
          ],
        });

        //监听排序
        table.on("sort(productionWorkOrderTable)", function (obj) {
          table.reload("productionWorkOrderTable", {
            initSort: obj,
            where: {
              sort: obj.field,
              order: obj.type,
            },
          });
        });
      } else if (obj.event === "createTask") {
        //生成研发任务
        createYFTask(data);
      }
    });

    //  生成研发任务
    function createYFTask(data) {
      data.workOrderCode = data.code;
      data.workOrderId = data.id;
      data.statusDesc = "待确认";
      admin.putTempData("workOrderData", data);

      let title = "添加研发质检任务";
      admin.formOpen({
        type: 1,
        area: ["48%", "70%"],
        style: "font-size: 20px;",
        title: title,
        path: "components/productionPlan/createTaskQualityForm.html",
        finish: function () {
          table.reload(insTb, {});
        },
      });
    }

    // 工单开工、暂停、关闭
    function operationWorkOrder(id, type, tips, data) {
      layer.confirm(
        tips,
        {
          offset: "65px",
          skin: "layui-layer-admin",
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "production/productionPlan/admin/productionPlan/operationWorkOrder",
            {
              id: id,
              type: type,
              recordId: data.productionPlanRecordId,
            },
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                table.reload("productionWorkOrderTable");
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "PUT"
          );
        }
      );
    }

    // 添加生产计划工单
    $("#productionWorkOrderBtnAdd").click(function () {
      admin.open({
        type: 1,
        area: "50%",
        offset: "145px",
        title: "添加生产开工单",
        content: $("#productionWorkOrderAddTemplate").html(),
        success: function () {
          //制造令列表
          admin.initDataSelect(
            "production/makeOrder/admin/makeOrder/getSelectList",
            null,
            "productionProcessDeviceId",
            null,
            "工站生产任务编号",
            "code",
            null
          );
          //制造令选择事件
          form.on(
            "select(selectProductionProcessDevice)",
            function (selectData) {
              let productionProcessDeviceId = selectData.value;
              // 获取工单详情
              admin.req(
                "production/makeOrder/admin/makeOrder/get",
                {
                  productionProcessDeviceId: productionProcessDeviceId,
                },
                function (res) {
                  if (res.code == 200) {
                    res.data.waitProductionQuantity =
                      res.data.planProductionQuantity - res.data.outputQuantity;
                    res.data.productionQuantity =
                      res.data.planProductionQuantity;
                    res.data.productionProcessDeviceId =
                      productionProcessDeviceId;
                    form.val("productionWorkOrderAddForm", res.data);
                    form.render();
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "GET",
                false
              );
            }
          );

          // 提交开工单
          form.on("submit(productionWorkPlanFormSubmit)", function (d) {
            let waitProductionQuantity = d.field.waitProductionQuantity;
            let claimQuantity = d.field.claimQuantity;
            if (claimQuantity === "") {
              layer.msg("认领数量不能为空", { icon: 2 });
              return false;
            }

            if (claimQuantity === "0") {
              layer.msg("认领数量不能为0", { icon: 2 });
              return false;
            }
            if (parseInt(claimQuantity) > parseInt(waitProductionQuantity)) {
              layer.msg("认领数量不能大于待排产数量", { icon: 2 });
              return false;
            }
            d.field.outputQuantity = d.field.claimQuantity;
            d.field.productionProcessDeviceId = d.field.id;
            d.field.productionQuantity = d.field.planProductionQuantity;
            layer.load(2);
            admin.req(
              "production/productionPlan/admin/productionWorkOrder/submitWorkOrder",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("makeOrderTable");
                  //清空数据
                  waitProductionQuantity = null;
                  claimQuantity = null;
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "POST",
              true,
              "application/json; charset=utf-8"
            );
            return false;
          });
        },
      });
    });

    // 详情弹窗
    function productionWorkOrderDetailModel(data) {
      admin.open({
        type: 1,
        area: ["83%", "810px"],
        title: "生产开工单信息",
        content: $("#productionWorkOrderTemplate").html(),
        success: function () {
          //开工单详情
          console.log(123, data);
          $("#imgDiv img").attr("src", data.drawUrl);

          // 开工单详情
          form.val("productionWorkOrderForm", data);
          // 领料记录
          table.render({
            id: "#receiptRecordTable",
            elem: "#receiptRecordTable",
            url:
              config.base + "enterprise/receiptRecord/admin/receiptRecord/list",
            where: { workOrderCode: data.code },
            page: true,
            toolbar: true,
            defaultToolbar: [],
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号", align: "center" },
                {
                  field: "code",
                  title: "领料单编号",
                  align: "center",
                  width: 160,
                },
                {
                  field: "warehouseTypeName",
                  align: "center",
                  title: "仓库类型",
                },
                {
                  field: "receiptWarehouseName",
                  align: "center",
                  title: "领料仓库",
                },
                { field: "receiptNum", align: "center", title: "领料料号数" },
                { field: "statusName", align: "center", title: "状态" },
                { field: "auditPersonName", align: "center", title: "审核人" },
                { field: "creatorName", align: "center", title: "领料人" },
                {
                  field: "createTime",
                  align: "center",
                  title: "领取时间",
                  width: 160,
                },
                {
                  align: "center",
                  toolbar: "#receiptRecordTabBar",
                  title: "操作",
                  width: 120,
                },
              ],
            ],
            done: function (res, curr, count) { },
          });

          // 领料记录工具条点击事件
          table.on("tool(receiptRecordTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "detail") {
              //详情
              receiptRecordDetail(data);
            }
          });

          // 领料记录详情弹窗
          function receiptRecordDetail(data) {
            admin.open({
              type: 1,
              area: ["1500px", "90%"],
              style: "font-size: 20px;",
              title: "领料记录详情",
              content: $("#receiptRecordDetailForm").html(),
              success: function () {
                //领料记录数据回显
                form.val("receiptRecordDetailForm", data);
                form.render();
                //领料明细表格
                table.render({
                  elem: "#receiptRecordDetailTable",
                  data: data.receiptRecordDetailList,
                  cellMinWidth: 100,
                  page: false,
                  cols: [
                    [
                      { type: "numbers", width: 50, title: "序号" },
                      { field: "skuCode", title: "物料编码", align: "center" },
                      {
                        field: "skuName",
                        title: "物料名称",
                        align: "center",
                        width: 150,
                      },
                      {
                        field: "skuSpec",
                        title: "物料规格",
                        align: "center",
                        width: 150,
                      },
                      {
                        field: "materialNatureName",
                        title: "物料类别性质",
                        align: "center",
                        width: 140,
                      },
                      {
                        field: "productTypeName",
                        title: "物料类别",
                        align: "center",
                        width: 140,
                      },
                      {
                        field: "baseUnitName",
                        title: "基础单位",
                        align: "center",
                      },
                      { field: "unitName", title: "计量单位", align: "center" },
                      {
                        field: "receiptNum",
                        title: "领取数量",
                        align: "center",
                        width: 140,
                        edit: "text",
                      },
                      {
                        field: "remark",
                        title: "备注",
                        align: "center",
                        width: 160,
                        edit: "text",
                      },
                    ],
                  ],
                });
              },
              finish: function () {
                table.reload("receiptRecordTable", {});
              },
            });
          }

          // 报工记录
          table.render({
            elem: "#reportWorkRecordTable",
            url:
              config.base +
              "production/productionPlan/admin/productionTheWorkOrder/list?workOrderId=" +
              data.id,
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号", align: "center" },
                {
                  field: "code",
                  title: "报工单编码",
                  align: "center",
                  width: 150,
                },
                {
                  field: "orderTypeDesc",
                  title: "开工单性质",
                  align: "center",
                },
                { field: "warehouseName", title: "入库仓库", align: "center" },
                { field: "workQuantity", title: "报工数量", align: "center" },
                {
                  field: "reportWorkCheckStatusName",
                  title: "自检状态",
                  align: "center",
                },
                {
                  field: "checkStatusDesc",
                  title: "审核状态",
                  align: "center",
                },
                { field: "statusDesc", title: "状态", align: "center" },
                {
                  align: "center",
                  toolbar: "#reportWorkOrderTableBar",
                  title: "操作",
                  width: 140,
                },
              ],
            ],
          });

          // 报工记录工具条点击事件
          table.on("tool(reportWorkRecordTable)", function (obj) {
            var data = obj.data;
            if (obj.event === "reportWorkDetail") {
              //详情
              reportWorkRecordDetail(data);
            }
          });

          // 报工记录详情弹窗
          function reportWorkRecordDetail(data) {
            admin.open({
              type: 1,
              area: ["1500px", "90%"],
              style: "font-size: 20px;",
              title: "报工记录详情",
              content: $("#reportWorkOrderDetailForm").html(),
              success: function () {
                //报工记录数据回显
                admin.req(
                  "production/productionPlan/admin/productionWorkOrder/getWorkOrderDetails",
                  {
                    workOrderId: data.workOrderId,
                  },
                  function (res) {
                    if (res.code == 200) {
                      form.val("reportWorkOrderDetailForm", res.data);
                      form.render();
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "GET"
                );

                $("#pictureDiv").html(
                  '<img src="' +
                  data.reportWorkPic +
                  '" alt="上传成功后渲染" style="max-width: 196px"><input type="hidden" name="reportWorkPic" value="' +
                  data.reportWorkPic +
                  '">'
                );
                $("#reportWorkRemark").val(data.remark);
                form.val("reportWorkOrderDetailForm", data);
                form.render();
              },
            });
          }

          // 质检记录列表
          table.render({
            elem: "#checkRecordTable",
            url:
              config.base +
              "production/quality/admin/taskQualityRecord/list?workOrderId=" +
              data.id,
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", title: "序号", align: "center" },
                {
                  field: "code",
                  title: "样品编码",
                  align: "center",
                  width: 160,
                },
                {
                  field: "taskCode",
                  title: "质检任务编码",
                  align: "center",
                  width: 180,
                },
                {
                  field: "workCode",
                  title: "所属工单/订单",
                  align: "center",
                  width: 160,
                },
                {
                  field: "planCode",
                  title: "所属计划",
                  align: "center",
                  width: 160,
                },
                {
                  field: "qualityTestingNatureName",
                  title: "质检性质",
                  align: "center",
                },
                { field: "categoryName", title: "质检分类", align: "center" },
                { field: "statusName", title: "检测状态", align: "center" },
                {
                  field: "qualityTestingResultName",
                  title: "判定结果",
                  align: "center",
                },
                {
                  field: "updateTime",
                  title: "检出时间",
                  align: "center",
                  width: 160,
                },
                {
                  align: "center",
                  toolbar: "#qualityTestingRecordTableBar",
                  title: "操作",
                  width: 100,
                },
              ],
            ],
          });
          let deviceTypeList = [];
          if (data && data.id) {
            deviceTypeList = data.drawInfos;
          }
          table.render({
            elem: "#drawImageTable",
            data: [...deviceTypeList],
            page: false,
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "drawName", title: "图片名称" },
                { field: "drawUrl", title: "图片地址" },
                {
                  title: "操作",
                  align: "center",
                  width: 160,
                  templet: function (d) {
                    return `<a class="layui-btn layui-btn-xs" type="button" lay-event="preview">预览</a>`;
                  },
                },
              ],
            ],
          });
          table.on("tool(drawImageTable)", function (obj) {
            if (obj.event === "preview") {
              admin.formOpen({
                title: "图片预览",
                area: ["80%", "80%"],
                content: `<div id='drawImage' style='overflow: hidden;height:100%;display:flex;justify-content: center;
'><img style="height:100%" src="${obj.data.drawUrl}"/></div>`,
                success: function () {
                  if (
                    obj.data.drawUrl &&
                    obj.data.drawUrl.indexOf(".pdf") !== -1
                  ) {
                    // $("#drawImage").height(1000);
                    PDFObject.embed(obj.data.drawUrl, "#drawImage");
                  } else {
                    $("#drawImage").height("auto");
                    $("#drawImage").html(
                      '<img style="max-width: 100%;max-height: 100%" src="' +
                      obj.data.drawUrl +
                      '"/>'
                    );
                  }
                },
              });
            }
          });
          // 质检记录工具条点击事件
          table.on("tool(checkRecordTable)", function (obj) {
            let data = obj.data;
            if (obj.event === "details") {
              //详情
              showDetailsModel(data);
            }
          });

          // 质检记录详情
          function showDetailsModel(data) {
            admin.putTempData("taskQualityRecordData", data);
            admin.formOpen({
              type: 1,
              area: ["80%", "92%"],
              style: "font-size: 20px;",
              title: "质检记录详情",
              path: "components/res/quality/taskQualityRecordDetailNoEditForm.html",
            });
          }
        },
      });
    }

    // 打印采购单
    function showPrintFinishedOrderTemplate(data) {
      admin.open({
        type: 1,
        area: ["1060px", "800px"],
        offset: '65px',
        title: '销售订单',
        content: $('#printFinishedOrderTemplate').html(),
        success: function () {
          let html = "";
          admin.req("production/productionPlan/admin/productionWorkOrder/getWorkOrderPrint/" + data.id, {}, function (res) {
            if (res.code === 200) {
              let orderItem = res.data;

              html += `
               <div class="print-ab-title">
                  <div class="print-img">
                       <img src="${orderItem.cardCode}" alt="">
                    
                    </div>
                 <div class="print-title">工序开工单</div>
                </div>
             
              <div class="print-header">
               <div class="header-content"> 
                     <div class="time">排产时间:${orderItem.planTime}</div>
            <div class="time">排产人:${orderItem.planName||'无'}</div>

                 <div class="time">基准书编号:${orderItem.bookCode}</div>
            </div>
              </div>
          </div>
          <div class="print-table">
            <div class="print-view">
            
              `;

              html += `
              <div class="print-nape nape-btm">
                <div class="btm-sign lt flex-1">
                <div class="img-list"> 
                    ${orderItem.drawUrls.map((item, index) => `

                       <img src="${item}" alt="">

                     `).join('')}
                  </div>
                  </div>
                <div class="sign-rt flex-1">
                      <div class="cell w-100">
                        <div class="name flex-1">制造令</div>
                        <div class="val flex-1">${orderItem.recordCode || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">工序名称</div>
                        <div class="val flex-1">${orderItem.processName || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">产品图号</div>
                        <div class="val flex-1">${orderItem.tuhao || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">订单号</div>
                        <div class="val flex-1">${orderItem.orderCode || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">产品名称</div>
                        <div class="val flex-1">${orderItem.proName || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">产品编码</div>
                        <div class="val flex-1">${orderItem.proCode || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">物料编码</div>
                        <div class="val flex-1">${orderItem.skuCode}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">生产数量</div>
                        <div class="val flex-1">${orderItem.quality || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">计划生产时间</div>
                        <div class="val flex-1">${orderItem.productTime || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">交货时间</div>
                        <div class="val flex-1">${orderItem.shipmentTime || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">创建人</div>
                        <div class="val flex-1">${orderItem.createName || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">工号</div>
                        <div class="val flex-1">${orderItem.creator || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">激活时间</div>
                        <div class="val flex-1">${orderItem.predictStartTime || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">计划完工时间</div>
                        <div class="val flex-1">${orderItem.predictFinishTime || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">机型</div>
                        <div class="val flex-1">${orderItem.deviceTypeName}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">夹具/量具</div>
                        <div class="val flex-1">${orderItem.fixture + '/' + orderItem.measuringTools || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">责任工种</div>
                        <div class="val flex-1">${orderItem.personnelWorkTypeName || ''}</div>
                      </div>
                      <div class="cell w-100">
                        <div class="name flex-1">工序要求</div>
                        <div class="val flex-1">${orderItem.processContent || ''}</div>
                      </div>
              
                  
                </div>
              </div>
            </div>
          </div>`
              $('#printHtml').html(html);

              $("#printPurchaseOrder").click(function () {
                $('#printHtml').print({
                  debug: false,
                  importCSS: true,
                  printContainer: true,
                  operaSupport: false
                });
              })
            }
          });
        }
      })
    }
  });
</script>
<style>
  .cardU {
    background-image: url(../../assets/images/card_u.png);
    background-repeat: no-repeat;
    background-position: center;
    width: 200px;
    height: 150px;
    margin-left: 0px;
    padding: 0;
  }

  .print-ab-title{
    position: relative;
    height: 90px;
    padding-bottom: 10px;
    .print-img{
    width: 80px;
    height: 80px;
    position: absolute;
    left: 1px;
    top: 10px;
    border: 1px solid #0b0707;
    img{
      width: 130%;
      height: 130%;
      position: absolute;
      transform: translate(-15%, -15%);

    }
    }
  }
  .print-header{
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    .header-content{
      width: 50%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    }
    
  }

  .my-print-box .print-view .btm-sign {
    height: 702px !important;
    width: 50%;
    padding-left: 10px;
  }

  .cardU img {
    width: 100%;
    height: 100%;
  }

  .hei-me{
    height: 150px;
  }

  .my-print-box .val, .my-print-box .print-view .print-nape .td{
    white-space: wrap;
  }
  .my-print-box .val, .my-print-box .print-view .print-nape .td{
    word-break: break-all;
  }
  .img-list {
  display: flex;
  flex-wrap: wrap;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 95%; /* Adjust as needed */
  height: 100%; /* Adjust as needed */;
  justify-content: space-between;
}

.img-list img {
  width: 210px;
  /* height: 210px; */
  object-fit: contain; /* 完整显示图片（不裁剪） */
  margin: 0;
}

/* 当只有一个 img 时，宽度 80%，高度 auto，完整显示 */
.img-list img:only-child {
  width: 80%;
  height: auto;       /* 高度自适应 */
  max-width: 80%;    /* 防止图片过大 */
  object-fit: contain; /* 完整显示图片（不裁剪） */
}
</style>